# coding=utf8
import json
import requests

from settings import SERVICE_TITLE, DINGDINGROBOT_URL
from tools.tianrui_tools import dingding_robot


class DingDingRobot(object):
    def __init__(self, url=None):
        if url:
            self.url = url
        else:
            self.url = DINGDINGROBOT_URL

    def send_text(self, message, level="error", atMobiles=[], isAtAll=False):
        if level == "error":
            level = "报警"
        else:
            level = "提示"

        content = "{}收到{}，{}".format(SERVICE_TITLE, level, message)

        response = dingding_robot(self.url, content, atMobiles=atMobiles, isAtAll=isAtAll)
        print(response)
